package calculatorView;

import java.awt.GridLayout;

import javax.swing.JFrame;
import javax.swing.JPanel;

import calculatorModel.Div;
import calculatorModel.Operation;
import calculatorModel.Sum;

public class TestArea {
	public static void main(String[] args) {

		JFrame frame = ExamplesUtils.createFrame();


		Operation operator = new Operation(new Sum());

		int[] element = new int[2];

		element[0] = 5;
		element[1] = 9;
		
		
		CalculatorArea area = new CalculatorArea(operator);
		
		JPanel panel = new JPanel();
		panel.setLayout(new GridLayout(2, 1));
		frame.getContentPane().add(panel);

		frame.setTitle("Area");
		frame.setSize(300, 300);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);// programma
																// termina
																// quando
																// qualcuno
																// chiude la
																// finestra

		frame.getContentPane().add(area.getArea());// il contentpane è il
													// pannello dei
		// contenuti(non bordi neri)
		frame.setVisible(true);



		try {
			int[] results = operator.doIntOperation(element);
		} catch (Exception e) {
			area.getArea().setText(null);
			area.getArea().insert("Error: divided by zero", 0);
		}

		int[] element1 = new int[2];

		element1[0] = 5;
		element1[1] = 0;

		operator.setOperator(new Div());
		
		try {
			int[] results1 = operator.doIntOperation(element1);
		} catch (Exception e) {
			area.getArea().setText(null);
			area.getArea().insert("Error: divided by zero", 0);
		}
	}

}
